﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Saxxon.LibDoomSharp.Lumps
{
    public class SidedefsEntry : SerializableBase
    {
        /// <summary>
        /// Length of a Sidedef table entry in bytes.
        /// </summary>
        public const int ENTRY_LENGTH = 30;

        /// <summary>
        /// X-offset of the texture.
        /// </summary>
        public Int16 TextureXOffset;

        /// <summary>
        /// Y-offset of the texture.
        /// </summary>
        public Int16 TextureYOffset;

        /// <summary>
        /// Upper texture name.
        /// </summary>
        public string TextureUpper;

        /// <summary>
        /// Lower texture name.
        /// </summary>
        public string TextureLower;

        /// <summary>
        /// Middle texture name.
        /// </summary>
        public string TextureMiddle;

        /// <summary>
        /// Sector number this sidedef faces.
        /// </summary>
        public Int16 Sector;

        /// <summary>
        /// Read Sidedef data.
        /// </summary>
        protected override void Read(Stream stream, int length)
        {
            DataReader reader = new DataReader(stream);
            TextureXOffset = reader.ReadInt16();
            TextureYOffset = reader.ReadInt16();
            TextureUpper = reader.ReadString(8);
            TextureLower = reader.ReadString(8);
            TextureMiddle = reader.ReadString(8);
            Sector = reader.ReadInt16();
        }

        /// <summary>
        /// Retrieve string representation of Linedef.
        /// </summary>
        public override string ToString()
        {
            return "Sidedef { Offset=" +
                TextureXOffset.ToString() + ", " + TextureYOffset.ToString() +
                "; Upper=" + TextureUpper +
                "; Lower=" + TextureLower +
                "; Middle=" + TextureMiddle +
                "; Sector=" + Sector.ToString() +
                "; }";
        }

        /// <summary>
        /// Write linedef data.
        /// </summary>
        protected override void Write(Stream stream)
        {
            DataWriter writer = new DataWriter(stream);
        }
    }
}
